package com.nulldev.util.networking.rudp;

import java.util.UUID;

import com.nulldev.util.networking.rudp.util.SerializationUtils;

public class Message {
	// The data that was received
	private volatile byte[] data;

	// Network type that was sent
	private volatile NetworkSendType networkSendType;

	// Sequence id of message
	private volatile int sequenceID;

	// connection id
	private volatile UUID connectionID;

	// Sequence number when splitting messages
	private volatile int splitMessageID;

	public byte[] getData() {
		return data;
	}

	public void setData(byte[] data) {
		this.data = data;
	}

	public NetworkSendType getNetworkSendType() {
		return networkSendType;
	}

	public void setNetworkSendType(NetworkSendType networkSendType) {
		this.networkSendType = networkSendType;
	}

	public int getSequenceID() {
		return sequenceID;
	}

	public void setSequenceID(int sequenceID) {
		this.sequenceID = sequenceID;
	}

	public UUID getConnectionID() {
		return connectionID;
	}

	public void setConnectionID(UUID connectionID) {
		this.connectionID = connectionID;
	}

	public int getSplitMessageID() {
		return splitMessageID;
	}

	public void setSplitMessageID(int splitMessageID) {
		this.splitMessageID = splitMessageID;
	}

	public <T> T read() {
		return SerializationUtils.getInstance().deserialize(this.data);
	}

	@Override
	public String toString() {
		return "Message[uuid=" + this.connectionID + ",seqID=" + this.sequenceID + ",smID=" + this.splitMessageID + "]";
	}
}
